﻿// Copyright (c) ZhangPeihang. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using LaserMark.DataAccess.Models;

namespace LaserMark.DataAccess.Service;
public class GCodeOrderService : IGCodeOrderService
{
    private IDBManager DBManager { get; }

    public GCodeOrderService(IDBManager dBManager)
    {
        DBManager = dBManager;
    }

    public Task<bool> AddAll(List<GCodeOrder> orders)
    {
        using (var db = DBManager.Create())
        {
            foreach (var item in orders)
            {
                db.Update(item);
            }
        }

        return Task.FromResult(true);
    }

    public Task<bool> Delete()
    {
        using (var db = DBManager.Create())
        {
            db.Delete<GCodeOrder>("where 1=1");
        }

        return Task.FromResult(true);
    }

    public Task<List<GCodeOrder>> GetAll()
    {
        using (var db = DBManager.Create())
        {
            return Task.FromResult(db.Query<GCodeOrder>().ToList());
        }
    }

    public async Task<bool> UpdateBatch(List<GCodeOrder> orders)
    {
        using (var db = DBManager.Create())
        {
            foreach (var item in orders)
            {
                var AA = await db.UpdateAsync(item);
            }
        }

        return true;
    }
}
